#include "Platform.h"
#include <QDir>
#include <QStandardPaths>

QString GetOraSupportDirInner()
{
#if WIN32
	const auto path1 = qgetenv("APPDATA") + R"(\OpenRA\)";
	const auto path2 = qgetenv("USERPROFILE") + R"(\Documents\OpenRA\)";
	if (QDir(path1).exists())
		return path1;
	if (QDir(path2).exists())
		return path2;
    return "";
#elif __linux__ || __unix__
	static_assert(false, "Linux/Unix not support now.")
#else
	static_assert(false, "Unknown operation system.")
#endif
}

const QString& Platform::GetOraSupportDir()
{
    static QString path = "";
    if (path.isEmpty())
        path = GetOraSupportDirInner();
    return path;
}

const QString& Platform::GetOraContentDir()
{
    static auto dir = GetOraSupportDir() + "Content/";
	if (!QDir(dir).exists())
		QDir().mkpath(dir);
	return dir;
}

const QString& Platform::GetOraMapDir()
{
    static auto dir = GetOraSupportDir() + "maps/";
	if (!QDir(dir).exists())
		QDir().mkpath(dir);
	return dir;
}

const QString& Platform::GetOraLogDir()
{
    static auto dir = GetOraSupportDir() + "Logs/";
	if (!QDir(dir).exists())
		QDir().mkpath(dir);
	return dir;
}
